package com.mc.algorithm;

import java.util.LinkedHashMap;

public class UglyNumber {
	public static int get(int index){
		if(index<1)
			return 0;
		if(index==1)
			return 1;
		int p2=0;
		int p3=0;
		int p5=0;
		int pos=1;
		int[] numbers = new int[index];
		numbers[0]=1;
		while(pos<index){
			int p2Num=0;
			int p3Num=0;
			int p5Num=0;
			p2Num=numbers[p2]*2;
			p3Num=numbers[p3]*3;
			p5Num=numbers[p5]*5;
			int min = Math.min(p2Num, Math.min(p3Num, p5Num));
			numbers[pos]=min;
			while(numbers[p2]*2<=numbers[pos])p2++;
			while(numbers[p3]*3<=numbers[pos])p3++;
			while(numbers[p5]*5<=numbers[pos])p5++;
			pos++;
		}
		LinkedHashMap<Character,Integer> map = new LinkedHashMap<Character,Integer>();
		return numbers[pos-1];
	}
	public static void main(String[] args) {
		int res = UglyNumber.get(7);
		System.out.println(res);
	}
}
